<template>
  <div>
    <Header></Header>
    <el-row  v-loading="loading"
             element-loading-text="拼命加载中"
             element-loading-spinner="el-icon-loading"
             element-loading-background="rgba(0, 0, 0, 0.8)">
      <el-col :span="8" v-for="film in films"  >
        <el-card :body-style="{ padding: '0px' }">
          <img :src="film.pic" class="image">
          <div style="padding: 14px;">
            <span>{{film.name}}</span>
            <div class="bottom clearfix">
              <time class="time">{{film.createdTime}}</time>
              <el-button type="text" class="button" @click="collection(film.id)">收藏</el-button>
              <el-button type="text" class="button" @click="filmDetail(film.id)">详情</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import Header from "../components/Header";
export default {
  name: "ItemRecommend.vue",
  components: {Header},
  data() {
    return {
      collectionForm:{
        id:'',
        filmId:'',
        CreatedUserId:''
      },
      films:{},
      user:this.$store.getters.getUser
    }
  },
  methods:{
    getFilms(){
      const _this = this
      _this.$axios.post("/film/recommend/"+this.user.id+"/item").then(res => {
        _this.films = res.data.data
      })
    },
    filmDetail(id){
      this.$router.push("/film/"+id)
    },
    collection(id){
      const _this = this
      this.collectionForm.filmId=id
      this.collectionForm.id=''
      this.collectionForm.createdUserId=this.$store.getters.getUser.id
      _this.$axios.post("/collection/add",this.collectionForm).then(res => {
        if(res.data.data===true){
          this.$message({
            showClose: true,
            message: res.data.message,
            type: 'success'
          });
        }else{
          this.$message.error("收藏失败");
        }
      })
    }
},
  created() {
    this.getFilms()
  },
}
</script>
<style scoped>
.mpage {
  margin: 0 auto;
  text-align: center;
}
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 50%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
</style>